/**
 * 
 * @param  url  请求的接口地址
 * @param  type   请求类型 (get/post)
 * @param  data     请求传递的参数  
 * @param  return   返回值是请求接口回调的数据   
 */
function promiseRequesrt(url, type = 'get', data = '') {
    const pResult = new Promise(function (fulfilled, rejected) {
        const xhr = new XMLHttpRequest();

        if (type.toLowerCase() === 'get') {
            xhr.open('get', `${url}?${data}`);
            xhr.send();
        } else {
            xhr.open('post', url);
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send(data);
        }

        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (/^2\d{2}$/.test(xhr.status)) {
                    fulfilled(xhr.response)
                } else if (/^(4|5)\d2/.test(xhr.status)) {
                    rejected(xhr.responseText)
                }
            }
        }
    })

    return pResult;
}